/**
 * 
 */
package net.efo.model;

import java.util.Calendar;
import java.util.Iterator;
import java.util.Vector;

/**
 * @author Pascal de Vink
 *
 */
public class ConcreteDocument extends Document {

	private int id;
	private String text;
	private Calendar creation_date;
	private Calendar last_edit_date;
	private String name;
	private Vector<Tag> tags;
	
	public ConcreteDocument() {
		this.tags = new Vector<Tag>();
	}
	
	/**
	 * @return the id
	 */
	public int getID() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setID(int id) {
		this.id = id;
		setChanged();
		notifyObservers();
	}
	/**
	 * @return the text
	 */
	public Object getContents() {
		return text;
	}
	/**
	 * @param text the text to set
	 */
	public void setContents(Object text) {
		this.text = (String)text;
		setChanged();
		notifyObservers();
	}
	/**
	 * @return the creation_date
	 */
	public Calendar getCreation_date() {
		return creation_date;
	}
	/**
	 * @param creation_date the creation_date to set
	 */
	public void setCreation_date(Calendar creation_date) {
		this.creation_date = creation_date;
		setChanged();
		notifyObservers();
	}
	/**
	 * @return the last_edit_date
	 */
	public Calendar getLast_edit_date() {
		return last_edit_date;
	}
	/**
	 * @param last_edit_date the last_edit_date to set
	 */
	public void setLast_edit_date(Calendar last_edit_date) {
		this.last_edit_date = last_edit_date;
		setChanged();
		notifyObservers();
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}
	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
		setChanged();
		notifyObservers();
	}
	
	public boolean addTag(Tag tag) {
		boolean add = this.tags.add(tag);
		setChanged();
		notifyObservers();
		return add;
	}
	
	public Vector<Tag> getTags() {
		return this.tags;
	}
	
	public void setTags(Vector<Tag> tags) {
		this.tags = tags;
		setChanged();
		notifyObservers();
	}
	
	public String toString() {
		String ret = "Name: "+this.name + ", creation date: "+this.creation_date.getTimeInMillis() + ", text: "+this.text;
		for (Iterator iter = this.tags.iterator(); iter.hasNext();) {
			Tag tag = (Tag) iter.next();
			ret += "\n " + tag.getName();
		}
		
		return ret;
	}
}
